﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Xml.Serialization;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
    public class InventoryCommand : Command, ICommandInfo
    {
        public override string HelpText { get { return "Lists all inventory items carried"; } }
        public override string Example { get { return "Inventory"; } }

        [NonSerialized, XmlIgnore]
        public static List<string> Words = new List<string>() { "INV", "INVENTORY" };

        public override List<string> FirstWords { get { return Words; } }

        [MethodVisible]
        public static List<PerceivedEventAndAudience> PerformMethod(CommandToPerform cmd, IGameThing source, IGameThing target, PropertyData args, PropertyData modifyingArguments)
        {
            List<PerceivedEventAndAudience> events = new List<PerceivedEventAndAudience>();
            GameChar chr = source as GameChar;

            EventToPerceive evt = new EventToPerceive()
            {
                Sources = new AssociatedIDCollection(chr.AssociatedID)
            };

            string inventoryString = string.Empty;

            if (chr._items == null)
            {
                inventoryString = "Nothing";
            }
            else
            {
                var items = chr.Items.ReadItems<Item>();

                inventoryString = items.BuildList(Environment.NewLine, (v) => String.Format("{0} - {1} ({2})", v.ShortName, v.ShortDescription, v.ThingType));
            }
            evt._event = new Event(inventoryString, ViewType.See);
            events.Add(new PerceivedEventAndAudience() { Audience = new AssociatedIDCollection(chr.AssociatedID), Event = evt });

            return events;
        }
    }
}
